home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / CONTROLG.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.6 KB  |  181 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.9  $
  6. //
  7. // Implementation of class TControlGadget.
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_CONTROLG_H)
  11. # include <owl/controlg.h>
  12. #endif
  13. #if !defined(OWL_GADGETWI_H)
  14. # include <owl/gadgetwi.h>
  15. #endif
  16. #if !defined(OWL_TOOLTIP_H)
  17. # include <owl/tooltip.h>
  18. #endif
  19.  
  20. OWL_DIAGINFO;
  21. DIAG_DECLARE_GROUP(OwlGadget);
  22.  
  23. //
  24. //
  25. //
  26. TControlGadget::TControlGadget(TWindow& control, TBorderStyle border)
  27. :
  28.   TGadget(control.Attr.Id, border)
  29. {
  30.   Control = &control;
  31.   Control->ModifyStyle(0, WS_CLIPSIBLINGS);  // Make sure relayout paints OK
  32.   TRACEX(OwlGadget, OWL_CDLEVEL, "TControlGadget constructed @" << (void*)this);
  33. }
  34.  
  35. //
  36. //
  37. //
  38. TControlGadget::~TControlGadget()
  39. {
  40.   Control->Destroy(0);
  41.   delete Control;
  42.   TRACEX(OwlGadget, OWL_CDLEVEL, "TControlGadget destructed @" << (void*)this);
  43. }
  44.  
  45. //
  46. //
  47. //
  48. void
  49. TControlGadget::SetBounds(const TRect& bounds)
  50. {
  51.   TRACEX(OwlGadget, 1, "TControlGadget::SetBounds() enter @" << (void*)this <<
  52.     " bounds = " << bounds);
  53.  
  54.   // Set the gadget bounds, then move & repaint the control
  55.   //
  56.   TGadget::SetBounds(bounds);
  57.   Control->SetWindowPos(0, Bounds, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE);
  58.  
  59.   TRACEX(OwlGadget, 1, "TControlGadget::SetBounds() leave @" << (void*)this <<
  60.     " bounds = " << bounds);
  61. }
  62.  
  63. //
  64. // Find out how big this control gadget wants to be. Calculated using the
  65. // base size to get the borders, etc. plus the control size.
  66. //
  67. void
  68. TControlGadget::GetDesiredSize(TSize& size)
  69. {
  70.   TRACEX(OwlGadget, 1, "TControlGadget::GetDesiredSize() enter @" << (void*)this <<
  71.     " size = " << size);
  72.   TGadget::GetDesiredSize(size);
  73.  
  74.   //    TRect rect = Control->GetWindowRect();
  75.  
  76.   if (ShrinkWrapWidth)
  77.     size.cx += Control->Attr.W;
  78.   if (ShrinkWrapHeight)
  79.     size.cy += Control->Attr.H;
  80.  
  81.   TRACEX(OwlGadget, 1, "TControlGadget::GetDesiredSize() leave @" << (void*)this <<
  82.     " size = " << size);
  83. }
  84.  
  85. //
  86. // Virtual called after the window holding a gadget has been created
  87. //
  88. void
  89. TControlGadget::Created()
  90. {
  91.   PRECONDITION(Window);
  92.   PRECONDITION(Window->GetHandle());
  93.  
  94.   // Create control is necessary
  95.   //
  96.   Control->SetParent(Window);
  97.   if (Window->GetHandle() && !Control->GetHandle()) {
  98.     Control->Create();
  99.     Control->ShowWindow(SW_SHOWNA);
  100.   }
  101.  
  102.   // Register control with the tooltip window (if there's one)
  103.   //
  104.   TTooltip* tooltip = Window->GetTooltip();
  105.   if (tooltip) {
  106.     CHECK(tooltip->GetHandle());
  107.  
  108.     // Register the control with the tooltip
  109.     //
  110.     if (Control->GetHandle()) {
  111.       TToolInfo toolInfo(Window->GetHandle(), Control->GetHandle());
  112.       tooltip->AddTool(toolInfo);
  113.     }
  114.   }
  115. }
  116.  
  117. //
  118. // Override the Inserted() virtual to take the oportunity to make sure that the
  119. // control window has been created and shown
  120. //
  121. void
  122. TControlGadget::Inserted()
  123. {
  124.   TRACEX(OwlGadget, 1, "TControlGadget::Inserted @" << (void*)this);
  125.   Control->SetParent(Window);
  126.   if (Window->GetHandle() && !Control->GetHandle()) {
  127.     Control->Create();
  128.     Control->ShowWindow(SW_SHOWNA);
  129.   }
  130. }
  131.  
  132. //
  133. // Override the Remove() virtual to take the oportunity to unparent the
  134. // control window from the owning Window
  135. //
  136. void
  137. TControlGadget::Removed()
  138. {
  139.   TRACEX(OwlGadget, 1, "TControlGadget::Removed @" << (void*)this);
  140.   Control->SetParent(0);
  141.   // Should we destroy the control at this point??
  142.   // Since it's no longer in the parent's child-list, there's a potential
  143.   // leak. However, the semantics of this function is 'Removed' - therefore
  144.   // one could be removing the control to be reinserted in another
  145.   // gadgetwindow.
  146.  
  147.   // Unregister ourself with the tooltip window (if there's one)
  148.   //
  149.   if (Window && Window->GetHandle()) {
  150.     TTooltip* tooltip = Window->GetTooltip();
  151.     if (tooltip) {
  152.       CHECK(tooltip->GetHandle());
  153.  
  154.       TToolInfo toolInfo(Window->GetHandle(), Control->GetHandle());
  155.       tooltip->DeleteTool(toolInfo);
  156.     }
  157.   }
  158. }
  159.  
  160. //
  161. // Invalidate a rectangle within this gadget by invalidating the rect in the
  162. // control window in addition to the owning Window
  163. //
  164. void
  165. TControlGadget::InvalidateRect(const TRect& rect, bool erase)
  166. {
  167.   TGadget::InvalidateRect(rect, erase);
  168.   if (Control->GetHandle())
  169.     Control->InvalidateRect(rect, erase);
  170. }
  171.  
  172. //
  173. // Cause our control window to paint now if possible
  174. //
  175. void
  176. TControlGadget::Update()
  177. {
  178.   if (Control->GetHandle())
  179.     Control->UpdateWindow();
  180. }
  181.